//
//  AXFServiceController.m
//  AXFEightGroup
//
//  Created by hgj on 2016/12/22.
//  Copyright © 2016年 ya. All rights reserved.
//

#import "AXFServiceController.h"
#import "AXFProblemController.h"

@interface AXFServiceController ()

@property (weak, nonatomic) IBOutlet UILabel *servicePhone_label;

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation AXFServiceController {
    NSString *_title;
}

- (instancetype)initWithTitle:(NSString *)title {
    if (self = [super init]) {
        _title = title;
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    self.navigationItem.title = _title;
    self.navigationItem.title = @"客服帮助";
    
    self.tableView.tableFooterView = [UIView new];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        
        [self callPhone];
        
    } else if (indexPath.row == 1) {
        
        [self.navigationController pushViewController:[AXFProblemController new] animated:YES];
    }
}

#pragma mark - 打电话 -
- (void)callPhone{
    
    NSString *message = [_servicePhone_label.text substringFromIndex:6];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:(UIAlertControllerStyleAlert)];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"拨打" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
        
        if (_webView) {
            _webView = [[UIWebView alloc] initWithFrame:CGRectZero];
        }
        [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://10010"]]];
    }];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
    [alert addAction:action];
    [alert addAction:cancel];
    [self showDetailViewController:alert sender:nil];
}

@end
